#include <QtGui/QApplication>
#include <QCoreApplication>
#include <QTextCodec>
#include <QFile>
#include <QPlastiqueStyle>
#include "mainwindow.h"
#include "setting.h"
#include "ldebug.h"
#include "encoderprovidermgr.h"
#include "encoderoptionmgr.h"
#include "encodercodec.h"
#include "encoderinterface.h"

#include <stdio.h>

QSettings global_settings;



int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    /* Setup style */
    a.setStyle(new QPlastiqueStyle());

    /* Set up for global LDEBUG */
    QFile stdout_r, stderr_r;
    stdout_r.open(stdout,QIODevice::WriteOnly);
    stderr_r.open(stderr,QIODevice::WriteOnly);
    LDebug dbg(&stdout_r,&stderr_r);

    /* Set up for settings */
    QCoreApplication::setOrganizationName("LFCInvention");
    QCoreApplication::setApplicationName("LFVEncoder");

    /* Set up for UTF-8 codec */
    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    codec->setCodecForCStrings(codec);
    codec->setCodecForLocale(codec);
    codec->setCodecForTr(codec);

    /* Meta type relations */
    qRegisterMetaType<EncoderCodec>("EncoderCodec");
    qRegisterMetaType<EncoderCodec *>("EncoderCodec *");
    qRegisterMetaType<EncoderInterface::Infomation>("EncoderInterface::Infomation");



    /* Set up for encoder library */
    EncoderProviderMgr encPrdMgr;
    encPrdMgr.addProviderSearchPath(QCoreApplication::applicationDirPath() + "/providers/encoders/");
    encPrdMgr.findAndRegisterProviders();

    /* Set up for encoder option mgr*/
    EncoderOptionMgr encOpMgr;

    /* Our main window */
    MainWindow w;
    w.show();

    /* Main loop */
    return a.exec();
}
